package com.lfx.concurrent;

import java.util.Random;

public class ServerThread2 extends Thread{

    private final Random random;

    private final LinkedBlockingQueueRequestQueue requestQueue;

    public ServerThread2(LinkedBlockingQueueRequestQueue requestQueue, final String name, long seed ) {
        super(name);
        this.random = new Random(seed);
        this.requestQueue = requestQueue;
    }


    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            Request request=requestQueue.getRequest();
            System.out.println(Thread.currentThread().getName()+" 处理 "+request);
            try {
                Thread.sleep(random.nextInt(1000));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
